package com.bhms.module.resources.village.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import com.bhms.module.resources.village.mapper.Business;
import com.bhms.module.resources.village.mapper.City;
import com.bhms.module.resources.village.mapper.Cycle;
import com.bhms.module.resources.village.mapper.CycleFace;
import com.bhms.module.resources.village.mapper.District;
import com.bhms.module.resources.village.mapper.Estates;
import com.bhms.module.resources.village.mapper.EstatesMapper;
import com.bhms.module.resources.village.mapper.Subway;
import com.bhms.module.resources.village.mapper.SubwayStation;
import com.sunshulin.util.PropertyUtils;

public class VillageServiceBean implements VillageService {

	private EstatesMapper estatesMapper;

	/**
	 * 根据拼音简拼查询小区
	 * 
	 * @param estates
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public String searchEstatesByJp(Estates estates) throws Exception {
		List<Estates> list = null;
		try {
			list = estatesMapper.selectEstates(estates);
		} catch (Exception e) {
			e.printStackTrace();
		}

		List jsonList = new ArrayList();
		for (Estates est : list) {
			Map parameters = new HashMap();
			parameters.put("displayName", est.getProjectname());
			parameters.put("displayValue", est.getProjectjianpin());
			parameters.put("datas", PropertyUtils.getValue(est));
			jsonList.add(parameters);

		}
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("autocomplete", jsonList);
		return jsonObject.toString();
	}

	/**
	 * 城市列表
	 * 
	 * @return
	 */
	@Override
	public List<City> searchCity(City city) {
		return estatesMapper.selectCity(city);
	}

	/**
	 * 根据城市名称，查询该地区
	 * 
	 * @param city
	 * @return
	 */
	@Override
	public List<District> searchDistrict(City city) {
		return estatesMapper.selectDistrict(city);
	}

	/**
	 * 根据地区名称，查询该地区下的商圈
	 * 
	 * @param district
	 * @return
	 */
	@Override
	public List<Business> searchBusiness(District district) {
		return estatesMapper.selectBusiness(district);
	}

	@Override
	public List<Cycle> searchCycle(City city) {
		return estatesMapper.selectCycle(city);
	}

	@Override
	public List<CycleFace> searchCycleFace() {
		return estatesMapper.selectCycleFace();
	}

	@Override
	public List<Subway> searchSubway(City city) {
		return estatesMapper.selectSubway(city);
	}

	@Override
	public List<SubwayStation> searchSubwayStation(Subway subway) {
		return estatesMapper.selectSubwayStation(subway);
	}

	public void setEstatesMapper(EstatesMapper estatesMapper) {
		this.estatesMapper = estatesMapper;
	}
}
